<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Hello, world!</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../css/font-awesome.min.css">
    <link rel="stylesheet" href="../fonts/iconfont.css">
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/bootstrap-select.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style>
        .bd-placeholder-img {
            font-size: 1.125rem;
            text-anchor: middle;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        @media (min-width: 768px) {
            .bd-placeholder-img-lg {
                font-size: 3.5rem;
            }
        }

        html,
        body {
            height: 100%;
        }

        body {
            padding-bottom: 40px;
            background-color: #fff;
        }

        .form-signin {
            width: 100%;
            max-width: 640px;
            margin: auto;
            padding: 15px;
        }

        .form-signin .checkbox {
            font-weight: 400;
        }
        .wareContent{
            display: flex;
            justify-content: center;
            align-items: center;
            position: relative;
        }
       
        .form-signin .form-control {
            position: relative;
            box-sizing: border-box;
            height: auto;
            padding: 10px;
            font-size: 16px;
        }

     
        .form-signin .form-control:focus {
            z-index: 2;
        }

        .form-signin input[type="email"] {
            margin-bottom: -1px;
            border-bottom-right-radius: 0;
            border-bottom-left-radius: 0;
        }

        .form-signin input[type="password"] {
            margin-bottom: 10px;
            border-top-left-radius: 0;
            border-top-right-radius: 0;
        }

        .sr-only2 {
            margin-top: 15px;
        }


        .logodiv img {
            width: 240px;
            margin: 0 auto;
            display: block;
        }

        .logodiv {
            text-align: center;
        }

        .logodiv h1 {
            font-size: 1.4rem;
            color: #03357a;
            margin-top: 20px;
            margin-bottom: 20px;
        }

        .logodiv h2 {
            font-size: 1.5rem;
            margin-bottom: 80px;
        }



        .fgtpaws {
            text-align: center;
            margin-top: 10px;
        }

        .btn {
            padding: 0.375rem 0.15rem
        }

        .btn-tiqu {
            width: 125px;
            margin: 0 auto;
            display: block;
        }

        .buytitle {
            font-size: 1.1rem;
            color: #03357a;
            margin-top: 20px;
        }

        .buytitle span {
            font-size: 1rem;
            color: #999;
        }

        .action-row button {
            margin-bottom: 15px;
        }

        .buysearch {
            font-size: smaller;
        }

        .formscreen .form-control-theme {
            font-size: smaller;
        }

        .action-row {
            position: fixed;
            width: 100%;
            bottom: 0;
            margin-top: 0;
            margin-bottom: 0;
            background: #fff;
            left: 0;
        }

        .container2 {
            padding: 10px;
            display: block;
            overflow: hidden;
        }

        .bootstrap-select {
            width: calc(100% - 0px) !important;
        }

        .formscreen .filter-option-inner-inner {
            font-size: smaller;
        }

        .myselect {
            width: calc(100% - 0px);
        }

        .btn-action:disabled,
        .btnsmall1:disabled {
            background: #D9D9DA !important;
            color: #808081 !important;
            border-color: #D9D9DA !important;
        }

        .buysearch {
            width: 100%;
            display: block;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="container2">



            <div class="modal fade fullmodal show"  style="display: block;background: #fff;"
                id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog  modal-dialog-scrollable">
                    <div class="modal-content">
                        <div class="modal-body">
                            <div class="logodiv">
                                <img class="bannerlogo pt-3" src="../image/logo.jpeg">
                                <h3 class="mt-3 mb-5">{{lan['Job_Issue']}}</h3>
                            </div>
                            <div class="row  align-items-center">



                                <div class="col-12 col-sm-6 col-md-3">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh  flex-shrink-0 filedlabel">{{lan['Issue_Date']}}
                                        </div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="date" v-model="searchdata.ArrivedDate"
                                                :placeholder="lan['Issue_Date_placeholder']"
                                                class="form-control form-control-theme" value="">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-12 col-sm-6 col-md-3">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Job_No']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="text" id="JobNum" v-model="searchdata.JobNum"
                                                :placeholder="lan['Job_No_placeholder']"
                                                class="form-control form-control-theme" value="">
                                        </div>
                                    </div>
                                </div>

                                <div class="col-12 col-sm-6 col-md-3">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Assembly']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="text" id="Assembly" v-model="searchdata.AssemblySeq"
                                                :placeholder="lan['Assembly_placeholder']"
                                                class="form-control form-control-theme" value="">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-12">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['User']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="text" v-model="searchdata.name" disabled
                                                class="form-control form-control-theme" value="">
                                        </div>
                                    </div>
                                </div>


                            </div>

                            <div class=" row justify-content-center mt-4">
                                <div class="col-4 col-md-4">
                                    <button type="button" onclick="loadData();" tapmode=""
                                        class="btn btn-primary btn-action">{{lan['OK']}}</button>
                                </div>


                                <div class="col-4 col-md-4">
                                    <button type="button" tapmode="" onclick="close_win()"
                                        class="btn btn-primary btn-action">{{lan['Cancel']}}</button>
                                </div>

                            </div>

                        </div>

                        <div class="modal-footer">
                            <div class="copyright">
                                <div class="row" :gutter="10">
                                    <div  class="col-5" style="text-align: right;">{{lan['Version']}}：</div>
                                    <div  class="col-7">{{appversion}}</div>
                                    <div  class="col-5"  style="text-align: right;">{{lan['Site']}}：</div>
                                    <div  class="col-7">{{SiteName}}</div>
                                    <div  class="col-5"  style="text-align: right;">{{lan['Company']}}：</div>
                                    <div  class="col-7">{{CompanyName}}</div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
             <div>
                <ul class="nav nav-tabs" id="myTab" role="tablist">
                    <li class="nav-item" role="presentation">
                        <a class="nav-link active " id="home-tab" data-toggle="tab" href="#home" role="tab"
                            aria-controls="home" aria-selected="true">{{lan['Mtl_List']}}</a>
                    </li>
                    <li class="nav-item" role="presentation">
                        <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab"
                            aria-controls="profile" aria-selected="false">{{lan['Return_List']}}</a>
                    </li>
    
                </ul>
                <div class="tab-content" id="myTabContent">
                    <div class="tab-pane  show active" id="home" role="tabpanel" aria-labelledby="home-tab">
                        <div class="buysearch buysearch2">
                            <div class="row   align-items-center">
            
                                <div class="col-6 col-sm-4 col-md-4">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Issue_Date']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            {{searchdata.ArrivedDate}}
                                        </div>
                                    </div>
                                </div>
            
                                <div class="col-6 col-sm-4 col-md-4">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Job_No']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            {{searchdata.JobNum}}
                                        </div>
                                    </div>
                                </div>
            
                                <div class="col-6 col-sm-4 col-md-4">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Assembly']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            {{searchdata.AssemblySeq}}
                                        </div>
                                    </div>
                                </div>
            
            
                            </div>
            
                        </div>
                        <h2 class="buytitle"><span>({{lan['Pls_select']}})</span></h2>
                        <button type="button" @click="list1_selectall()"
                        class="btn btn-link">{{lan['Select_All']}}</button>
                        <div  class="row align-items-center">
                            <div v-for="(item,index) in goodlist" :key="'shou'+index" v-if="item.shoucai == 1" id="shouitem"
                                class="col-12 col-sm-6 col-md-4">
                                <div class="d-flex bd-highlight align-items-start">
                                    <div class="pt-2 bd-highligh">
                                        <div class="custom-control custom-switch">
                                            <!-- 请选择 -->
                                            <input :disabled="Lot_btn" type="checkbox" v-model='item.itemChecked' @change="toshou(item,index)" class="custom-control-input"
                                                :id="'Switch'+item.JobMtl_JobNum+'-'+item.JobMtl_PartNum+'-'+item.JobMtl_MtlSeq">
                                            <label class="custom-control-label"
                                                :for="'Switch'+item.JobMtl_JobNum+'-'+item.JobMtl_PartNum+'-'+item.JobMtl_MtlSeq"></label>
                                        </div>
                                    </div>
                                    <div class="pt-2 flex-grow-1 bd-highlight">
                                        <table class="table table-buy table-borderless table-sm">
                                            <tr>
                                                <td class="ttl">{{lan['Mtl_Seq']}}</td>
                                                <td class="ttl">{{lan['Part']}}</td>
                                                <td class="ttl">{{lan['Delivered_Qty']}}</td>
                                            </tr>
                                            <tr>
                                                <td >{{item.JobMtl_MtlSeq}}</td>
                                                <td>{{item.JobMtl_PartNum}}</td>
                                                <td>{{processNumber(item.JobMtl_IssuedQty,item.NumOfDec)}}</td>
                                            </tr>
                                            <tr>
                                                <td colspan="3"  class="ttl">{{lan['Desc']}} </td>
                                                
                                            </tr>
                                            <tr>
                                                <td colspan="4">{{item.JobMtl_Description}}</td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                            </div>
    
                        </div>
                    </div>
                    <div class="tab-pane " id="profile" role="tabpanel" aria-labelledby="profile-tab">
                        <div class="buysearch buysearch2">
                            <div class="row   align-items-center">
            
                                <div class="col-6 col-sm-4 col-md-4">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Issue_Date']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            {{searchdata.ArrivedDate}}
                                        </div>
                                    </div>
                                </div>
            
                                <div class="col-6 col-sm-4 col-md-4">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Job_No']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            {{searchdata.JobNum}}
                                        </div>
                                    </div>
                                </div>
            
                                <div class="col-6 col-sm-4 col-md-4">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Assembly']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            {{searchdata.AssemblySeq}}
                                        </div>
                                    </div>
                                </div>
            
            
                            </div>
            
                        </div>
                        <h2 class="buytitle"><span>({{lan['Cancel']}})</span></h2>
                        <button type="button" @click="list2_selectall()"
                        class="btn btn-link">{{lan['Un_Select_All']}}</button>
                        <div  class="row   align-items-center">
                            <div v-for="(item,k) in goodlist" :key="'cai'+k" v-if="item.shoucai == 2" id="caiitem"
                                class="col-12 col-sm-6 col-md-4">
                                <div class="d-flex bd-highlight align-items-start">
                                    <div class="pt-2 bd-highligh">
                                        <div class="custom-control custom-switch">
                                            <!-- 请选择 -->
                                            <input :disabled="Lot_btn" type="checkbox" @change="toshou(item,k)" class="custom-control-input"
                                                :id="'Switch'+item.JobMtl_JobNum+'-'+item.JobMtl_PartNum+'-'+item.JobMtl_MtlSeq">
                                            <label class="custom-control-label"
                                                :for="'Switch'+item.JobMtl_JobNum+'-'+item.JobMtl_PartNum+'-'+item.JobMtl_MtlSeq"></label>
                                        </div>
                                    </div>
                                    <div class="pt-2 flex-grow-1 bd-highlight">
                                        <table class="table table-buy table-borderless table-sm">
                                            <tr>
                                                <td class="ttl">{{lan['Mtl_Seq']}}</td>
                                                <td class="ttl">{{lan['Part']}}</td>
                                                <td class="ttl">{{lan['Delivered_Qty']}}</td>
                                            </tr>
                                            <tr>
                                                <td style="min-width: 80px;">{{item.JobMtl_MtlSeq}}</td>
                                                <td>{{item.JobMtl_PartNum}}</td>
                                                <td>{{processNumber(item.JobMtl_IssuedQty,item.NumOfDec)}}</td>
                                            </tr>
                                            <tr>
                                                <td colspan="3"  class="ttl">{{lan['Desc']}} </td>
                                                <td rowspan="4" style="vertical-align: center;text-align: center;"><i v-if="!Lot_btn" @click="addPartChange(item,k)" class="iconfont icon-add"></i></td>
                                                
                                            </tr>
                                            <tr>
                                                <td colspan="3">{{item.JobMtl_Description}}</td>
                                            </tr>
                                           
                                        </table>
                                        <div class="d-flex bd-highlight align-items-center" v-if="goodlist[k].list.length > 0"  v-for="(item1,index1) in goodlist[k].list" :key="index1">
                                            <div class="pt-2 flex-grow-1 bd-highlight">
                                                <table class="table table-buy table-borderless table-sm">
                                                    <tr>
                                                        <td  style="width: 45%;" class="ttl">{{lan['WareHouseCode']}}</td>
                                                        <td  style="width: 45%;"  class="ttl">{{lan['BinNum']}}</td>
                                                        <td></td>
                                                    </tr>
                                                    <tr  class="allinput">
                                                        <td style="width: 45%;">
                                                            <div class="wareContent">
                                                                <input   v-if="!item1.warehouseFlag" type="text"
                                                                :disabled = "Lot_btn"
                                                                v-model="goodlist[k].list[index1].WareHouseCode"
                                                                @click="warehouseFocus(item,k,item1,index1)"
                                                                class="form-control form-control-num" value="">
                                                                <select  v-if="item1.warehouseFlag"
                                                                :disabled="Lot_btn"
                                                                @change="binNumChange(item,k,item1,index1)" v-model="goodlist[k].list[index1].WareHouseCode" 
                                                                    class="form-control"    data-live-search="true">
                                                                    <option v-for="(item2,index2) in item.WareHouseCodeList" :key="index2" 
                                                                        :value="item2.Warehse_WarehouseCode" :data-name="item2.Warehse_WarehouseCode">
                                                                        {{item2.Warehse_WarehouseCode}}</option>
                                                                </select>
                                                                <i v-if="!item1.warehouseFlag" style="margin-left: 5px;" @click="onWareQuery(item1,index1)" class="iconfont icon-scan"></i>
                                                                <i v-if="item1.warehouseFlag" style="margin-left: 5px;" @click="onWareScan(item1,index1)" class="iconfont icon-query"></i>
                                                            </div>
                                                        </td>
                                                        <td  style="width: 45%;">
                                                            <div class="wareContent">
                                                                <input   v-if="!item1.binFlag" type="text"
                                                                @click="binFocus(item,k,item1,index1)"
                                                                :disabled = "Lot_btn"
                                                                v-model="goodlist[k].list[index1].BinNum"
                                                                class="form-control form-control-num" value="">
                                                                <select v-if="item1.binFlag"  
                                                                    :disabled="Lot_btn"
                                                                    @change="numChange(item,k,item1,index1)"   v-model="goodlist[k].list[index1].BinNum" 
                                                                    class="form-control" data-live-search="true">
                                                                    <option v-for="(item2,index2) in item1.BinNumList" :key="index2"  :value="item2.WhseBin_BinNum" >
                                                                        {{item2.WhseBin_BinNum}}
                                                                    </option>
                                                                </select>
                                                                <i  v-if="!item1.binFlag" style="margin-left: 5px;" @click="onBinQuery(item1,index1)" class="iconfont  icon-scan"></i>
                                                                <i  v-if="item1.binFlag" style="margin-left: 5px;" @click="onBinScan(item1,index1)" class="iconfont icon-query"></i>
                                                            </div>
                                                        </td>
                                                        <td></td>
                                                    </tr>
                                                </table>
                                                <table  class="table table-buy table-borderless table-sm">
                                                    <tr>
                                                        <td style="width: 30%;"  class="ttl">{{lan['Lot']}}</td>
                                                        <td style="width: 30%;"  class="ttl">{{lan['Qty']}}</td>
                                                        <td  style="width: 30%;" class="ttl"></td>
                                                    </tr>
                                                    <tr>
                                                        <td >
                                                            <div class="wareContent">
                                                                <input  type="number"
                                                                v-if="item1.lotFlag"
                                                                @blur="lotBlur(item,k,item1,index1)"
                                                                :disabled="!item.Part_TrackLots || Lot_btn"
                                                                v-model="item1.LotNum"
                                                                class="form-control form-control-num" value="">
                                                                <input  type="number"
                                                                v-if="!item1.lotFlag"
                                                                :disabled="!item.Part_TrackLots || Lot_btn"
                                                                @click="lotFocus(item,k,item1,index1)"
                                                                v-model="item1.LotNum"
                                                                class="form-control form-control-num" value="">
                                                                <i  v-if="!item1.lotFlag" style="margin-left: 5px;" @click="onLotQuery(item1,index1)" class="iconfont  icon-scan"></i>
                                                                <i  v-if="item1.lotFlag" style="margin-left: 5px;" @click="onLotScan(item1,index1)" class="iconfont icon-query"></i>

                                                            </div>
                                                        </td>
                                                        <td  style="width:80px;" style="display: flex;align-items: center;">
                                                            <div class="wareContent">
                                                                <input  type="number"
                                                                :disabled="Lot_btn"
                                                                @input="checkDecimal(item,k,item1,index1)"
                                                                @change="checkNum(item,k,item1,index1)" 
                                                                :step="item.AllowDecimals ? 'any' : '1'"
                                                                v-model="item1.OnhandQty"
                                                                class="form-control form-control-num" value="">
                                                                <span> {{item.IUM}}</span>
                                                            </div>
                                                        </td>
                                                       
                                                        <td>
                                                            <button type="button" tapmode="" @click="toSerial(item,k,item1,index1)" :disabled="!item.Part_TrackSerialNum"
                                                                :class=" item.Part_TrackSerialNum == false ? 'btn-secondary':'btn-primary'"
                                                                class="btn btn-primary  btn-block">{{lan['Serial_No']}} <span
                                                                class="badge badge-light">{{item1.SerialNum.length}}</span>
                                                            </button>
                                                        </td>
                                                        <td>
                                                    </tr>
                                                </table>
                                            </div>
                                            <div class="pt-2 bd-highligh">
                                                <i  v-if="!Lot_btn" @click="removePartChange(item,k,item1,index1)" class="iconfont icon-delete"></i>
                                            </div>

                                        </div>
                                      
                                    </div>
                                </div>
                            </div>
    
    
                        </div>
                    </div>
                    <!-- <div class="scrollable-scrollbar">
                        <div class="scrollable-track"></div>
                        <div class="scrollable-thumb"></div>
                    </div> -->
                </div>
             </div>


        </div>


        <div style="height:100px;"></div>
        <div class="action-row">
            <div class="container">
                <div class=" row justify-content-center">
                    <div class="col-4 col-md-4">
                        <button type="button" tapmode="" :disabled="receipt_btn" @click="checksubmit();"
                            class="btn btn-primary btn-action">{{lan['Confirm']}}</button>
                    </div>
                    <div class="col-4 col-md-4">
                        <button type="button" @click="print_label();" :disabled="print_btn" tapmode=""
                            class="btn btn-primary btn-action">{{lan['Print_Label']}}
                        </button>
                    </div>

                    <div class="col-4 col-md-4">
                        <button type="button" tapmode="" onclick="close_win1();"
                            class="btn btn-primary btn-action">{{lan['Cancel']}}
                        </button>
                    </div>


                </div>

            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/lang.js"></script>
<script type="text/javascript" src="../script/model.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/vue.min.js"></script>
<script type="text/javascript" src="../script/jquery.min.js"></script>
<script type="text/javascript" src="../script/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="../script/bootstrap-select.min.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/createReturnBarcode.js"></script>
<script type="text/javascript">
    var postcount = 0;
    var returncount = 0;
    var postlist = [];
    var tagspostcount = 0;
    var tags = [];
    var updatesn = [];
    var printsn = [];

    const app = new Vue({
        el: '#app',
        data: {
            list: [],
            goodlist: [],
            goodkeys: {},
            screenwidth: document.body.clientWidth,
            vendors: [],
            Lot_btn:false,
            requirenum: 0,
            scannum: 0,
            BinNum: "",
            searchdata: {
                name: '',
                JobNum: '',//2468
                ArrivedDate: timenow(),
                AssemblySeq: '0',
                VendorName: '',
                PONum: '',
                BinNum: '',
                WarehouseCode: '',
            },
            uinfo: {},
            lotinfo: {},
            PartNumTrackSerialNum: {},
            firstFocus: false,
            //postlist: [],
            //postlistids: [],
            create_btn: false,
            receipt_btn: true,
            print_btn: true,
            confirm_btn:false,
            print_num: '',
            allsn: {},
            AllSerialNum: [],
            lb: {},
        },
        mounted() {
            const that = this
            window.onresize = () => {
                return (() => {
                    that.screenwidth = document.body.clientWidth
                })()
            }
            this.showmodal();
            setTimeout(function () {
                $("#JobNum").focus();
            }, 500);

            //init_select();
        },
        onShow() {

        },
        methods: {
            checkNum: function (item, index,item1,index1) {
                var OnhandQty = processNumber(this.goodlist[index].list[index1].OnhandQty,this.goodlist[index].NumOfDec);
                if (OnhandQty <= 0) {
                    OnhandQty = 1;

                }
                this.$set(this.$data.goodlist[index].list[index1], 'OnhandQty', OnhandQty);
            },
            list1_selectall(){
                for (let i = 0; i < this.goodlist.length; i++) {
                    this.goodlist[i].shoucai = 2;
                }
            },
            list2_selectall(){
                for (let i = 0; i < this.goodlist.length; i++) {
                    this.goodlist[i].shoucai = 1;
                }
            },
            toSerial: function (item, index,item1,index1) {
                var data = {};
                item1.SerialNum = []
                item1.PartNum = item.PartNum;
                item1.PartDescription = item.PartDescription;
                var InputOurQty = processNumber(item1.OnhandQty, item.NumOfDec);
                for (let i = 0; i < InputOurQty; i++) {
                    item1.SerialNum.push({
                        'type': i+1,
                        'SerialNumber': '',
                    })
                }
                data.post = item1;
                data.index = index;
                data.index1 = index1;
                data.post.Lot_btn = app.Lot_btn;
                data.post.snsCheck = app.snsCheck;
                data.post.JobNum = app.searchdata.JobNum
                data.post.index = index;
                data.post.index1 = index1;
                data.searchdata = this.searchdata;
                data.title = lan['Order_Material_Return'];
                data.frame = "sn_order_material_return";
                data.right = [{
                    text: lan["Scan"],
                    color: '#fff',
                }];
                console_debug(data,"sn_order_material_return");

                openNavWin2(data.frame, data);

            },
            checkDecimal(ite,k,item, index) {
                if(item.WarehouseCode == ""){
                    api.toast({
                        msg: lan['WareHouseCode_placeholder'],
                        location: 'middle'
                    });
                    item.OnhandQty=""
                    return;
                }
                if(item.BinNum == ""){
                    api.toast({
                        msg: lan['BinNum_placeholder'],
                        location: 'middle'
                    });
                    item.OnhandQty=""
                    return;
                }
                if(ite.Part_TrackLots && item.LotNum == ""){
                    api.toast({
                        msg: lan['LotNum_placeholder'],
                        location: 'middle'
                    });
                    item.OnhandQty=""
                    return;
                }
                // 获取输入的值
                let inputValue = item.OnhandQty;

                // 将输入值解析为浮点数
                let parsedValue = parseFloat(inputValue);

                // 如果解析成功，限制小数位数不超过 NumOfDec
                if (!isNaN(parsedValue)) {
                    const decimalCount = (inputValue.toString().split('.')[1] || "").length || 0;
                    if (decimalCount > item.NumOfDec) {
                    // 超过 NumOfDec 位小数，截取前 NumOfDec 位小数，不进行四舍五入
                    inputValue = inputValue.substring(0, inputValue.indexOf('.') + item.NumOfDec + 1);
                    }
                    item.OnhandQty = inputValue;
                    let totalOnhandQty = 0;
                    for(let ite of app.goodlist) {
                        for(let item of ite.list) {
                            let onhandQty = parseFloat(item.OnhandQty);
                            totalOnhandQty += onhandQty;
                        }
                    }
                    if(totalOnhandQty > ite.IssuedQty){
                        api.toast({
                            msg:lan['return_issued_placeholder'],
                            location: 'middle',
                        })
                        item.OnhandQty = 0
                        return
                    }
                    this.check_canclick()
                }
            },
            onWareQuery(item,index){
                item.warehouseFlag = true;
            },
            onWareScan(item,index){
                item.warehouseFlag = false;
            },
            onBinQuery(item,index){
                item.binFlag = true;
            },
            onBinScan(item,index){
                item.binFlag = false;
            },
            onLotQuery(item,index){
                item.lotFlag = true;
            },
            onLotScan(item,index){
                item.lotFlag = false;
            },
            addPartChange(item,k){
                loadWarehouseCodeData(item,k);
            },
            removePartChange(item,index,item1,index1){
                if (this.goodlist[index].list && this.goodlist[index].list.length > 0) {
                    this.goodlist[index].list.splice(index1, 1);
                }
            },
            binNumChange:function(item,index,item1,index1){
                   
                setTimeout(function(){
                    loadBinData(item,index,item1,index1)
                },100)
                   
            },
            numChange:function(item,index,item1,index1){
                setTimeout(function(){
                    loadPartNumStatus(item,index,item1,index1)
                },100)
            },
            lotFocus:function(item,index,item1,index1){
                if(item.WarehouseCode == ""){
                    api.toast({
                        msg: lan['WareHouseCode_placeholder'],
                        location: 'middle'
                    });
                    return;
                }
                if(item.BinNum == ""){
                    api.toast({
                        msg: lan['BinNum_placeholder'],
                        location: 'middle'
                    });
                    return;
                }
                setTimeout(function(){
                    scan3(item,index,item1,index1)
                },100)
            },
            lotBlur:function(item,index,item1,index1){
                if(item.WarehouseCode == ""){
                    api.toast({
                        msg: lan['WareHouseCode_placeholder'],
                        location: 'middle'
                    });
                    return;
                }
                if(item.BinNum == ""){
                    api.toast({
                        msg: lan['BinNum_placeholder'],
                        location: 'middle'
                    });
                    return;
                }
                loadPartNumStatus(item,index,item1,index1)
            },
            warehouseFocus:function(item,index,item1,index1){
                setTimeout(function(){
                    scan1(item,index,item1,index1)
                },100)
            },
            binFocus:function(item,index,item1,index1){
                if(item.WarehouseCode == ""){
                    api.toast({
                        msg: lan['WareHouseCode_placeholder'],
                        location: 'middle'
                    });
                    return;
                }
                setTimeout(function(){
                    scan2(item,index,item1,index1)
                },100)
            },
            check_canclick: function () {
                var canclick = false;
                var tc = false;
                var sr = false;
                var tg = false;
                var sc = true;
                for (i in this.goodlist) {
                    if (this.goodlist[i].shoucai == 2) {
                        console.log(1111111)
                        for(let i1 in this.goodlist[i].list){
                            let item =this.goodlist[i].list[i1]
                            if(!item.OnhandQty){
                                tg = true;
                            }
                            if (this.goodlist[i].is_SerialNum == 1) {
                                console.log(this.receipt_btn,22222)
                                if (item.SerialNum.length == 0) {
                                    sr = true;
                                }
                            }
                            if (this.goodlist[i].is_Lot == 1) {
                                if (!item.LotNum || item.LotNum == '') {
                                    tc = true;
                                }
                            }

                        }
                        sc = false;
                    }

                }
            
                if (tc  || tg  || sc || sr) {
                    canclick = true;
                }

                this.receipt_btn = canclick;
                console.log(this.receipt_btn,11111)
            },
            toshou: function (item,index) {
                var i = index;
                console.log(JSON.stringify(userinfo),222222)
                console.log(JSON.stringify(item),111111)
                var shoucai = this.goodlist[i].shoucai == 1 ? 2 : 1;
                if(shoucai == 2){
                    loadWarehouseCodeData(item,index)
                }
                console_debug(i, shoucai);
                var that = this;
                var unk = 0;           
                // if (item.Calculated_ReceivedTo == "PUR-UKN") {
                //     unk = 1;
                //     that.$set(that.$data.goodlist[i], 'is_Lot', 2);
                //     that.$set(that.$data.goodlist[i], 'is_SerialNum', 2);
                // }
                if (that.goodlist[i].is_Lot != -1) {
                    setTimeout(function () {
                        that.$set(that.$data.goodlist[i], 'shoucai', shoucai);
                        that.check_canclick()
                    }, 500)
                    if(item.shoucai == 1){
                        that.$set(that.$data.goodlist[i], 'list', []);
                        item.itemChecked = false;
                    }
                    return;
                }
               

            },
            print_label: function () {
                var btns = [];
                btns.push(lan['Print_Carton_Label']); //箱条码
                if(printsn.length > 0){
                    btns.push(lan['Print_SN_Label']);
                }
                var that = this;
                api.actionSheet({
                    title: lan['Tips'],
                    cancelTitle: lan['Cancel'],
                    buttons: btns
                }, function (ret, err) {
                    var index = ret.buttonIndex;
                    var key = index - 1;

                    if (btns[key] == lan['Print_Carton_Label']) {

                        print_type = 2;
                        that.print_carton();
                    }

                    if (btns[key] == lan['Print_SN_Label']) {
                        print_type = 1;
                        that.submit_sncode();
                    }
                });
            },
            async print_carton() {
                showProgress(lan['Loading']);
                print_tags = [];
                let ExpiryDate = ""
                console.log(JSON.stringify(this.goodlist),33333)
                for (let key in this.goodlist) {
                    console.log(JSON.stringify(key), 11111)
                    if (this.goodlist[key].shoucai == 2) {
                        let item = this.goodlist[key];
                        console.log(JSON.stringify(item), 222222)
                        for (let item1 in item.list) {
                            item.list[item1].LabelNum = item.PartNum + "/" +  item.list[item1].LotNum;
                            item.list[item1].PartNum = item.PartNum;
                            item.list[item1].PartDescription = item.PartDescription;
                            item.list[item1].BinNumList = [];
                            item.list[item1].JobNum = app.searchdata.JobNum;
                            item.list[item].IUM = item.IUM
                            print_tags.push(item.list[item1]);
                        }
                    }
                }
                hideProgress();
                if (print_tags.length > 0) {
                    open_printpage2(print_tags, 1, 1, 2,0);
                } else {
                    api.toast({
                        msg: lan['No_Data_Submit'],
                        location: 'middle'
                    });
                }
            },
            load_ExpirationDate(item) {

                return new Promise((resolve) => {

                    api.ajax({
                        url: server + 'Erp.BO.LotSelectUpdateSvc/LotSelectUpdates(' + userinfo.Company + ',' + item.PartNum + ',' + item.LotNum + ')',
                        method: 'get',
                        returnAll: false,
                        headers: {
                            'Authorization': userinfo.Token,
                            'Content-Type': 'application/json;charset=utf-8'
                        },
                        data: {}
                    }, function (ret, err) {
                        ajaxing = 0;
                        console_debug(ret, err);
                        //hideProgress();
                        var ExpirationDate = "";
                        if (ret) {
                            ExpirationDate = formatted_time(ret.ExpirationDate);
                        }
                        resolve(ExpirationDate);
                    });



                })

            },
            load_ProdCode(item) {

                return new Promise((resolve) => {

                    api.ajax({
                        url: server + 'Erp.BO.PartSvc/Parts(' + userinfo.Company + ',' + item.PartNum + ')',
                        method: 'get',
                        returnAll: false,
                        headers: {
                            'Authorization': userinfo.Token,
                            'Content-Type': 'application/json;charset=utf-8'
                        },
                        data: {}
                    }, function (ret, err) {
                        ajaxing = 0;
                        console_debug(ret, "Erp.BO.PartSvc/Parts");
                        var ProdCode = "";
                        if (ret) {
                            ProdCode = ret.ProdCode;
                        }
                        resolve(ProdCode);

                    });



                })

            },
            
            submit_sncode() {
                print_tags = printsn;
                if (print_tags.length > 0) {
                    open_printpage(print_tags, 1, 3);
                } else {
                    api.toast({
                        msg: lan['No_Data_Submit'],
                        location: 'middle'
                    });
                }

            },
            showmodal: function () {
                if (this.screenwidth < 576) {
                    $('#exampleModal').modal('show');
                    //init_select();
                } 
            },
            hidemodal: function () {
                $('#exampleModal').modal('hide');
            },
        }
    });
    apiready = function () {
        api.parseTapmode();
        server = getapi();
        back_listen();
        app.vendors = get_prefs_data("Vendors");
        app.uinfo = get_user_info();
        userinfo = get_user_info();

        app.searchdata.name = userinfo.Name;


        api.addEventListener({ name: 'navitembtn' }, function (ret, err) {
            if (ret.type == 'left') { close_win1(); }
            if (ret.type == 'right') { scan(); }

        });
        api.addEventListener({
            name: 'sn_order_material_return'
        }, function (ret, err) {
            if(ret && ret.value){
                var snposts = ret.value;
                console.log(JSON.stringify(snposts),33333)
                app.goodlist[snposts.index].list[snposts.index1].OnhandQty = snposts.OnhandQty;
                app.goodlist[snposts.index].list[snposts.index1].SerialNum = snposts.SerialNum;
                app.check_canclick()
                console.log(JSON.stringify(app.goodlist),44444)
                api.closeWin({name: 'sn_order_material_return'});
            }
        });
        setTimeout(function () {
            init_select();
        }, 200);
        api.addEventListener({
            name: 'infrared_scanning'
        }, function (ret, err) {
            $("input:focus").val(ret.value.str);
            app.searchdata.JobNum =  $("#JobNum").val();
            console.log(JSON.stringify(ret));
            if (ret && ret.value && ret.value.str && is_scan == 0) {
                app.searchdata.JobNum = ret.value.str;
            }

          
        });

      

        api.addEventListener({
            name: 'keyback',
            extra: {
                slidBackIntercept: true    
            }
        }, function (ret, err) {
            close_win1()

        });


    }

    //物料批号到期时间接口
    function PartLotAttribute(item){
        new Promise((resolve) => {

            api.ajax({
                url: server + 'BaqSvc/WMS_PartLotAttribute/?CompanyID='+userinfo.Company +'&PartNum='+item.JobMtl_PartNum+'&LotNum='+item.LotNum,
                method:'get',
                returnAll:false,
                headers: {
                    'Authorization': userinfo.Token,
                    'Content-Type': 'application/json;charset=utf-8'
                },
                data: {}
            }, function(ret, err){
                var ExpiryDate = ""
                if(ret && ret.value.length >0){
                    if(ret.value[0].PartLot_ExpirationDate != null){
                        ExpiryDate = formatted_time(ret.value[0].PartLot_ExpirationDate)
                    } 
                }
                resolve(ExpiryDate);
            })
        })
        
    };
    async function loadWarehouseCodeData(data,k) {
        userinfo = get_user_info();
        if (!userinfo.Token) {
            return;
        }
        await api.ajax({
            url: server + 'BaqSvc/WMS_WarehouseForPart/?CompID=' + userinfo.Company + "&Site=" + userinfo.Site +"&PartNum="+data.PartNum,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {}
        }, function (ret, err) {
            console.log(JSON.stringify(ret), 22222)
            if (ret && ret.value.length > 0) {
                app.$set(app.$data.goodlist[k],'WareHouseCodeList',ret.value)
                const item = itemdata({});
                app.goodlist[k].list.push(item);
            }
        });
    }
    function close_win1() {
        var msg = app.confirm_btn ? lan['cancel_tips'] : lan['cancel_tips'];
        if (app.confirm_btn) {
            api.confirm({
                title: lan['Tips'],
                msg: msg,
                buttons: [lan['NO'], lan['YES'], lan['Cancel']]
            }, function (ret, err) {
                var index = ret.buttonIndex;
                if (index == 2) {
                    checksubmit();
                } else if (index == 1) {
                    close_win();
                }
            });
        } else {
            close_win();
        }


    }


    function init_select() {
        $('.myselect1').selectpicker();
        $('.myselect2').selectpicker();
    }


    function scan() {

        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    //alert(ret.content);
                    if (app.goodlist.length > 0) {
                        loadqrData(ret.content);
                    } else {
                        $("input:focus").val(ret.content);
                        app.searchdata.JobNum = ret.content;
                    }

                }

            } else {
                //alert(JSON.stringify(err));
            }
        });
    }

    function loadData() {
        userinfo = get_user_info();
        var filter = "?CompID=" + userinfo.Company ;
        filter += "&AssemblySeq=" + app.searchdata.AssemblySeq;
        filter += "&Site=" + userinfo.Site;
        app.goodlist = [];
        if (!app.searchdata.JobNum) {
            api.toast({
                msg: lan['Job_No_placeholder'],
                location: 'middle'
            });
            return;
        }
        if(app.searchdata.JobNum){
            filter += "&JobNum=" + app.searchdata.JobNum;
        }
        console_debug(filter, '');
        showProgress(lan['Loading']);

        api.ajax({
            url: server + 'BaqSvc/WMS_JobMtlIssued/' + filter,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {},
        }, function (ret, err) {
            ajaxing = 0;
            console_debug(ret, err);
            if (ret && ret.value) {
                let rets=[]
                rets = ret.value
                var newlist = init_list(rets);
                if (newlist.length == 0) {
                    hideProgress();
                    api.toast({
                        msg: "no data !",
                        location: 'middle'
                    });
                    return;
                }
                app.goodlist = app.goodlist.concat(newlist);
                hideProgress();
                app.confirm_btn = true
                $('#exampleModal').modal('hide');


            } else {
                hideProgress();
                api.toast({
                    msg: "no data!",
                    location: 'middle'
                });
            }

        });
    }
 
    function init_list(data) {
        var ret = [];
        for (i in data) {
            if (parseInt(data[i].JobMtl_AssemblySeq) == parseInt(app.searchdata.AssemblySeq) && processNumber(data[i].JobMtl_IssuedQty,data[i].NumOfDec) > 0) {
              
                data[i].IssuedQty =  processNumber(data[i].JobMtl_IssuedQty,data[i].NumOfDec);
                data[i].OnhandQty = 0;
                data[i].LotNum  = "";
                data[i].PartNum = data[i].JobMtl_PartNum;
                data[i].MtlSeq = data[i].JobMtl_MtlSeq
                data[i].PartDescription = data[i].JobMtl_Description;
                data[i].NumOfDec = data[i].UOM_NumOfDec;
                data[i].shoucai = 1;
                data[i].list = [];  
                data[i].WareHouseCodeList = [];
                data[i].is_Lot = -1; //批号判断 -1 未查询  1 需创建 2 不需创建
                data[i].is_SerialNum = -1; //序列号判断 -1 未查询  1 需创建 2 不需创建
                if (data[i].Part_TrackLots) {
                    data[i].is_Lot = 1
                } else {
                    data[i].is_Lot = 2
                }
                if (data[i].Part_TrackSerialNum) {
                    data[i].is_SerialNum = 1; 
                } else {
                    data[i].is_SerialNum = 2; 
                }
                data[i].IUM = data[i].JobMtl_IUM;
                ret.push(data[i]);
            }

        }
        return ret;
    }
    function itemdata(data){
        data.WareHouseCode='';
        data.BinNum='';
        data.MaxQty='';
        data.LotNum='';
        data.OnhandQty='';
        data.SerialNum=[];
        data.BinNumList = [];
        data.warehouseFlag=false;
        data.binFlag=false;
        data.lotFlag=false;

        return data
    }
  
    function checksubmit() {
        let hasNegativeQty = false;

        for (let i = 0; i < app.goodlist.length; i++) {
            const item = app.goodlist[i];
            if (
            item.shoucai === 2 &&
            item.PartClass_NegQtyAction === "Stop" &&
            item.list.length > 0
            ) {
            for (let j = 0; j < item.list.length; j++) {
                const listItem = item.list[j];
                if(item.Part_TrackSerialNum && listItem.SerialNum.length == 0){
                    api.toast({  
                        msg: lan['Serialnum_placeholder'],  
                        location: 'middle'  
                    });
                    return
                }
                if(item.Part_TrackLots && !listItem.LotNum){
                    api.toast({  
                        msg: 'LotNum is required',  
                        location: 'middle'  
                    });
                    return
                }
                if(!listItem.OnhandQty){
                    api.toast({  
                        msg: 'Quantity is required',  
                        location: 'middle'  
                    });
                    return
                }
                if (processNumber(listItem.OnhandQty,item.NumOfDec) > processNumber(listItem.MaxQty,item.NumOfDec)) {
                    const message = `Order: ${item.OrderRel_OrderNum}, Line: ${item.OrderRel_OrderLine}. Part: ${item.PartNum}. Warehouse: ${listItem.WareHouseCode}. Bin: ${listItem.BinNum}. This transaction will result in a negative onhand quantity for the bin.`;
                    api.confirm({
                        title: lan["Tips"],
                        msg: message,
                        buttons: ["", lan["YES"]],
                    },function (ret, err) {
                        // 用户点击了 "YES"，继续提交数据或执行相应的操作
                        // 在这里编写用户点击 "YES" 后的处理逻辑
                        });
                    hasNegativeQty = true;
                    break; // 提示一次后停止继续检查
                }
            }
            }
        }

        if (!hasNegativeQty) {
            for (let i = 0; i < app.goodlist.length; i++) {
                const item = app.goodlist[i];
                if (item.shoucai === 2 && item.PartClass_NegQtyAction === "Warn" && item.list.length > 0) {

                    for (let j = 0; j < item.list.length; j++) {
                        const listItem = item.list[j];
                        if(item.Part_TrackSerialNum && listItem.SerialNum.length == 0){
                            api.toast({  
                                msg: lan['Serialnum_placeholder'],  
                                location: 'middle'  
                            });
                            return
                        }
                        if(item.Part_TrackLots && !listItem.LotNum){
                            api.toast({  
                                msg: 'LotNum is required',  
                                location: 'middle'  
                            });
                            return
                        }
                        if(!listItem.OnhandQty){
                            api.toast({  
                                msg: 'Quantity is required',  
                                location: 'middle'  
                            });
                            return
                        }
                        if (processNumber(listItem.OnhandQty,item.NumOfDec) > processNumber(listItem.MaxQty,item.NumOfDec)) {
                            const message = `This transaction will result in a negative onhand quantity for Part: ${item.PartNum}, Bin: ${listItem.BinNum}. Do you want to continue?`;
                            api.confirm(
                            {
                                title: lan["Tips"],
                                msg: message,
                                buttons: [lan["NO"], lan["YES"], lan["Cancel"]],
                            },
                            function (ret, err) {
                                var index = ret.buttonIndex;
                                if (index === 2) {
                                    submitfrom();
                                    // 用户点击了 "YES"，继续提交数据或执行相应的操作
                                    // 在这里编写用户点击 "YES" 后的处理逻辑
                                } else if (index === 1) {
                                    // close_win();
                                    // 用户点击了 "NO"，返回原页面或执行相应的操作
                                    // 在这里编写用户点击 "NO" 后的处理逻辑
                                }
                            }
                            );
                            return; // 提示一次后停止继续检查
                        }
                    }
                }
            }

            submitfrom();
        }
    }
    function submitfrom() {
        postlist = [];
        printsn = [];
        returncount = 0;
        postcount = 0;
        for (i in app.goodlist) {
            var item = app.goodlist[i];
            if(item.shoucai == 2){
                for(i1 in item.list){
                    
                    let item1 = item.list[i1]
                    
                    if(item.Part_TrackSerialNum && item1.SerialNum.length == 0){
                        api.toast({  
                            msg: lan['Serialnum_placeholder'],  
                            location: 'middle'  
                        });
                        return
                    }
                    if(item.Part_TrackLots && !item1.LotNum){
                        api.toast({  
                            msg: 'LotNum is required',  
                            location: 'middle'  
                        });
                        return
                    }
                    if(!item1.OnhandQty){
                        api.toast({  
                            msg: 'Quantity is required',  
                            location: 'middle'  
                        });
                        return
                    }
                    var row = {
                        "CompanyID": userinfo.Company,
                        "PlantID": userinfo.Site,
                        "UserName": userinfo.Name,
                        "Password": userinfo.password,
                        "TranDate": app.searchdata.ArrivedDate,
                        "PartNum":item.PartNum,
                        "UM": item.IUM,
                        "WarehouseCode": item1.WareHouseCode,
                        "BinNum": item1.BinNum,
                        "TranQty": item1.OnhandQty,
                        "JobNum": app.searchdata.JobNum,
                        "AssemblySeq": app.searchdata.AssemblySeq,
                        "JobSeq": item.MtlSeq,
                        "LotNum": item1.LotNum
                    }
                    var arr = [];
                    if (item1.SerialNum.length > 0) {
                        var SerialNum = item1.SerialNum;
                        for (k in SerialNum) {
                            var row1 = {};
                            row1.SerialNumber = SerialNum[k].SerialNumber;
                            arr.push(row1)
                            var sn = get_new_arr(item1.SerialNum);
                            sn.LabelNum =item.PartNum + "/" +item1.LotNum ;
                            sn.WareHouseCode = item1.WarehouseCode;
                            sn.BinNum = item1.BinNum;
                            sn.LotNum = item1.LotNum;
                            sn.SNStatus = 'INVENTORY';
                            sn.JobNum = app.searchdata.JobNum;
                            sn.AssemblySeq = 0;
                            sn.MtlSeq = 0;
                            printsn.push(sn);
                        }
                    }
                    if (arr.length > 0) {
                        row.SelectedSerialNumbers = arr;
                    }
                    postlist.push(row);

                }
               

            }
           
        }

        if (!postlist) {
            api.toast({
                msg: lan['No_Data_Submit'],
                location: 'middle'
            });
            return;
        }
        var datalist = {};
        for (i in postlist) {
            var item = postlist[i]
            var key = item.PartNum + item.JobSeq + item.WareHouseCode + item.BinNum + item.LotNum;
            if (datalist[key]) {
                datalist[key].TranQty = datalist[key].TranQty + item.TranQty;
                if (datalist[key].SelectedSerialNumbers) {
                    datalist[key].SelectedSerialNumbers = datalist[key].SelectedSerialNumbers.concat(item.SelectedSerialNumbers);
                } else {
                    datalist[key].SelectedSerialNumbers = item.SelectedSerialNumbers;
                }
            } else {
                datalist[key] = item;
            }
        }
        var postrows = [];
        for (key in datalist) {
            postrows.push(datalist[key]);
        }

        postcount = postrows.length;

        if (ajaxing) { return; } showProgress(lan['Loading']);
        for (i in postrows) {
            submit_issuemtl(postrows[i]);
        }




    }
    async function loadBinData(item,index,item1,index1) {
        userinfo = get_user_info();
        $('.myselect4').selectpicker('destroy'); // 先销毁
        await api.ajax({
            url: server + 'BaqSvc/WMS_WhseBin/?CompID=' + userinfo.Company + "&WarehouseCode=" + item1.WareHouseCode,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {

            }
        }, function (ret, err) {
            if (ret && ret.value.length > 0) {
               app.$set(app.$data.goodlist[index].list[index1],'BinNumList',ret.value)
                setTimeout(function () {
                    app.check_canclick()
                }, 200)
            }

        });
    }
    function loadPartNumStatus(item,index,item1,index1){
        userinfo = get_user_info();
        let filter = "?CompID=" + userinfo.Company;
        if (item.PartNum) {
            filter += "&PartNum=" + item.PartNum;
        }
        if(item1.WareHouseCode){
            filter += "&WhseCode=" + item1.WareHouseCode;
        }
        if(item1.BinNum){
            filter += "&Bin=" + item1.BinNum;
        }
        if(item1.LotNum){
            filter += "&LotNum=" + item1.LotNum;
        }
        api.ajax({
            url: server + 'BaqSvc/WMS_PartBinOnhand/' + filter,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {} 
        },function(ret,err){
            console.log(filter,44444)
            console.log(JSON.stringify(ret),111111)
            console.log(JSON.stringify(err),222222)
            if(ret && ret.value.length>0){
                app.check_canclick()
                if(item.Part_TrackLots && item1.LotNum != ""){
                    app.$set(app.$data.goodlist[index].list[index1],'MaxQty',processNumber(ret.value[0].PartBin_OnhandQty,item.NumOfDec)) 
                }
                if(!item.Part_TrackLots){
                    app.$set(app.$data.goodlist[index].list[index1],'MaxQty',processNumber(ret.value[0].PartBin_OnhandQty,item.NumOfDec))   
                }    
            }else{
                app.$set(app.$data.goodlist[index].list[index1],'MaxQty',0) 
            }
        })
    }   
    
    function submit_issuemtl(data1) {
        api.ajax({
            url: wmsserver + 'returnmtl/',
            method: 'post',
            returnAll: false,
            headers: {
                'token': wmstoken,
                'Content-Type': 'application/json;charset=utf-8'
            },
            //dataType: 'text',
            data: {
                body: create_submit_data(data1)
            }
            //data: {values: data1}
        }, function (ret, err) {
            ajaxing = 0;
            console_debug(ret, err);

            if (ret && ret.code == 1) {
                returncount++;
                if (returncount == postcount) {
                    api.alert({
                        title: lan['Tips'],
                        msg: lan['Submitted_successfully']
                    }, function (ret, err) {
                        app.receipt_btn = true
                        app.Lot_btn = true
                        app.print_btn = false
                        hideProgress();
                    });
                }
            } else {
                app.receipt_btn = true
                hideProgress();
                errMassage(ret.msg)
            }

        });

    }


    function scan1(item,index,item1,index1){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.$set(app.$data.goodlist[index].list[index1],'WareHouseCode',ret.content)
                    setTimeout(function(){
                        loadBinData(item,index,item1,index1)
                    },300)
                }
            } 
        });
          
    }
    function scan2(item,index,item1,index1){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.$set(app.$data.goodlist[index].list[index1],'BinNum',ret.content)
                    setTimeout(function(){
                        loadPartNumStatus(item,index,item1,index1)
                    },300)
                }
            } 
        });
          
    }
    function scan3(item,index,item1,index1){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.$set(app.$data.goodlist[index].list[index1],'LotNum',ret.content)
                    setTimeout(function(){
                        loadPartNumStatus(item,index,item1,index1)
                    },300)
                }
            } 
        });
          
    }

</script>

</html>